<template>
  <div>
    <Head></Head>
    <van-search
  v-model="value"
  shape="round"
  placeholder="查询菜品"
  @keydown.enter="search"
/>
<div>
  <div v-for="item in list" :key="item.id" class="list" @click="to({id:item.id})">
    <div class="img"><img :src="'http://124.93.196.45:10001/'+item.imgUrl" alt=""></div>
    <div>
      <div>{{item.name}}</div>
      <div style="font-size:18px;margin-top:5px"><van-icon name="fire-o" color="red" size="16px"/>{{item.score}} <span style="font-size:16px">￥</span><span>{{item.avgCost}}/人</span></div>
      <div v-for="item in item.productList" :key="item.id" @click="to({id:item.sellerId})">
        <div style="margin-top:8px">
          <img :src="'http://124.93.196.45:10001/'+item.imgUrl" alt="" style="width:100px">
        </div>
        <div style="font-size:18px;margin-top:5px ;">{{item.name}}</div>
        <div style="font-size:18px;margin-top:5px;color:red">￥{{item.price}}</div>
      </div>
      <div class="introduction">{{item.introduction}}</div>
    </div>

  </div>
</div>
  </div>
</template>

<script>
import  Head  from "./takeView/headView.vue"
import { searchlist,restaurantlist } from "./service";
import mixin from "../../mixin/flag"
export default {
  mixins:[mixin],
  data(){
    return{
      value:'',
      list:[]
    }
  },
components:{
  Head
},
methods:{
async search(){
  let res= await searchlist({keyword:this.value})
  this.list=res.data.rows.slice(0,1)
},
to(id){
    this.$router.push({path:'/restaurantDetail',query:id})
  },
},

async mounted(){
  this.value=this.$route.query.keyword
  if(this.value){
    
  let res= await searchlist({keyword:this.value})
this.list=res.data.rows.slice(0,1)
  console.log(res);
  }else{
    let res2=await restaurantlist({themeId:this.$route.query.id})
    this.list=res2.data.rows
    console.log(res2);
  }
  
}
}
</script>

<style lang="scss" scoped>
.list{
  width: 90%;
  // height: 180px;
  display: flex;
  font-size: 20px;
  margin: 10px auto;
  padding: 15px 10px;
background-color: white;
border-radius: 15px;
justify-content: space-between;
  .img{
    // display: block;
    width: 80px;
    height: 80px;
    overflow: hidden;
    border-radius: 15px;
    border-right: 1px solid white;;
    
    img{
      width: 80px;
      height: 80px;
    }
  }
  .introduction{
    margin-top: 10px;
    font-size: 18px;
    width: 250px;
    overflow:hidden;
    text-overflow:ellipsis;
    margin-right: -10px;
    white-space: nowrap;
  }
}
</style>